package thar.main;

//import android.app.Activity;
import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout; 
import android.widget.Toast;
import android.widget.ZoomControls; 

public class THAR_mapActivity extends MapActivity implements View.OnClickListener {
	MapController mc;
    GeoPoint p;
    private LocationManager lm;
    private LocationListener locationListener;
    private MapView mapView;
    Button b = null;
	
    /** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.map);
	    
	    
	    b = (Button) findViewById(R.id.button2);
	    b.setOnClickListener(this);
	    
	    lm = (LocationManager) 
	            getSystemService(Context.LOCATION_SERVICE);    
	        
	        locationListener = new MyLocationListener();
	        
	        lm.requestLocationUpdates(
	            LocationManager.GPS_PROVIDER, 
	            0, 
	            0, 
	            locationListener);
	    
	    
	    
	    mapView = (MapView) findViewById(R.id.mapview);
	    mapView.setBuiltInZoomControls(false);
	    // mapView.set
	    
	    List<Overlay> mapOverlays = mapView.getOverlays();
	    Drawable drawable = this.getResources().getDrawable(R.drawable.circle_black);
	    HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this);
	    
	    GeoPoint point = new GeoPoint(19240000,-99120000);
	    OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
	    
	    GeoPoint point2 = new GeoPoint(59330000, 18050000);
	    OverlayItem overlayitem2 = new OverlayItem(point2, "Hej!", "I'm in Sweden!");
	    
	    itemizedoverlay.addOverlay(overlayitem);
	    itemizedoverlay.addOverlay(overlayitem2);
	    mapOverlays.add(itemizedoverlay);
	    
	    mc = mapView.getController();
	    p = new GeoPoint(
	            (int) (59330000), 
	            (int) (18050000));
	 
	    mc.animateTo(p);
	    mc.setZoom(18); 
	    mc.stopPanning();
	   	}
	
	
    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
    
    @Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
    	Intent intent = new Intent(THAR_mapActivity.this, CustomActivity.class);
        startActivity(intent);

	}
    
    
    private class MyLocationListener implements LocationListener 
    {
        @Override
        public void onLocationChanged(Location loc) {
            if (loc != null) {
                Toast.makeText(getBaseContext(), 
                    "Location changed : Lat: " + loc.getLatitude() + 
                    " Lng: " + loc.getLongitude(), 
                    Toast.LENGTH_SHORT).show();
                p = new GeoPoint(
        	            (int) (loc.getLatitude()* 1E6), 
        	            (int) (loc.getLongitude() * 1E6 ));
        	 
        	    mc.animateTo(p);
        	    mapView.invalidate();
            }
        }

        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onStatusChanged(String provider, int status, 
            Bundle extras) {
            // TODO Auto-generated method stub
        }
    }
    
}
